<template>
	<view style="flex: 1;">
		<view @click="pickerShow = true">
			<slot>打开</slot>
		</view>
		<u-datetime-picker v-if="pickerType==='time'" :show="pickerShow" v-model="timePickerVal" :mode="timeType" @cancel="pickerClose" @confirm="pickerConfirm"/>
		<u-picker v-else :show="pickerShow" :columns="columns" :keyName="keyName" @confirm="pickerConfirm" @cancel="pickerClose"/>
	</view>
	
</template>

<script>
	export default {
		desc:'picker',
		props:{
			pickerType:{
				type:String,
				default:'picker'
			},
			timeType:{
				type:String,
				default:'datetime'
			},
			columns:{
				type:Array
			},
			keyName:{
			  type:String,
			  default:'name'
			}
		},
		data() {
			return {
				pickerShow:false,//显示
				timePickerVal: Number(new Date()),//时间绑定值
			}
		},
		methods:{
			pickerConfirm(e){
				// console.log("确定",e)
				if(this.pickerType === 'time'){
					
					this.$emit("pickerChange",e.value)
				}else{
					this.$emit("pickerChange",e.value[0])
				}
				this.pickerShow = false
			},
			pickerClose(){
				// console.log("pickerClose")
				this.pickerShow = false
			}
		}
	}
</script>

<style>
</style>